<template>
    <div @click.stop="loadMore" id="LoadMore">
      <ul>
        <li v-if="nowPage<lastPage">
          {{$t('mall.loadMore')}}
        </li>
        <li v-else>
          {{$t('mall.noMore')}}
        </li>
      </ul>
    </div>
</template>

<script>
    export default {
        name: "LoadMore",
      methods:{
        loadMore(){
            // console.log('点击加载。。。。')
          if(this.nowPage<this.lastPage) {
            this.getProductClass(this.categoryId,this.$store.getters.getSearchContent);
          }
        },
        getProductClass(nowCategoryID,search){
          //获取分类下的产品
         if(nowCategoryID===-1){
           nowCategoryID=null;
         }
          this.$store.dispatch('toChangeLoadIngVisible',true);
          let _this=this;
          let pageNum=parseInt(_this.nowPage)+1;
          this.axios.get(domain.url+'product/api/get_product_list', {
            params: {
              language: _this.lang,
              page:pageNum,
              limit:6,
              category_id:nowCategoryID,
              search:search,
            }
          })
            .then(function (response){
              _this.nowPageTemp=response.data.list.current_page;
              _this.lastPageTemp=response.data.list.last_page;
              _this.$store.dispatch('toAddProducts',response.data.list.data);
              _this.$store.dispatch('toChangeLoadIngVisible',false);
            })
            .catch(function (error) {
              console.log(error);
            });
        }
      },
      watch:{
        mallProductList: function(oldValue, newValue) {
          this.nowPageTemp=-1;
          this.lastPageTemp=-1
        }
      },
      computed: {
        mallProductList:{
          get(){
            return this.$store.getters.getMallProductList;
          },
          set(){}
        },
        nowPage: {      //当前页的页数，如果为空则默认返回1
          get() {
            if (this.loadMoreInfo === null||this.loadMoreInfo===undefined||this.loadMoreInfo==='null') {
              return 1;
            }
            else {
              if (this.nowPageTemp !== -1) {
                return this.nowPageTemp;
              }
              return this.loadMoreInfo.current_page;
            }
          },
          set() {
          }
        },
        lastPage: {         //剩余页的页数，如果为空则默认返回1
          get() {
            if (this.loadMoreInfo === null||this.loadMoreInfo===undefined||this.loadMoreInfo==='null') {
              return 1;
            } else {
              if (this.lastPageTemp !== -1) {
                return this.lastPageTemp;
              }
              return this.loadMoreInfo.last_page;
            }
          },
          set() {
          }
        },
        lang:{
            get(){
                let storageData = window.sessionStorage.getItem('lang');
                if(this.$store.state.lang!==storageData&&storageData!=='null'){
                    this.$store.dispatch('toChangeLang', storageData);    //同步操作
                }
                return this.$store.getters.getLang;
            },
            set(){}
        }
      },
      data(){
        return{
          nowPageTemp:-1,
          lastPageTemp:-1,
        }
      },
      props:{
        categoryId:Number,
        loadMoreInfo:{}
      }
    }
</script>

<style scoped>
#LoadMore{
  color:#999999;
  background: #f5f5f5;
  height:50px;
  width:100%;
  line-height: 50px;
  font-size:13px;
  letter-spacing: 1px;
  padding-bottom: 10px;
  cursor: pointer;
}
</style>
